<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加</title>
<link rel="stylesheet" href="${ctx}/static/js/layui/css/layui.css">
<style type="text/css">
	.msg{
		color : red !important;
	}
</style>
</head>
<body>
	<div style="padding: 10px;">
		<form class="layui-form" action="">
			<input type="hidden" name="pid" value="0">
			<div class="layui-form-item">
				<label class="layui-form-label">菜单名称</label>
				<div class="layui-input-block">
					<input type="text" name="menuName" required
						lay-verify="required" placeholder="请输入菜单名称" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">菜单类型</label>
				<div class="layui-input-block">
					<select name="menuType" lay-verify="required">
						<option value="目录" selected="selected">目录</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">权限标识符</label>
				<div class="layui-input-inline">
					<input type="text" name="permission" placeholder="请输入权限标识符" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">菜单图标</label>
				<div class="layui-input-inline">
					<input type="text" name="icon" required 
						lay-verify="required" placeholder="请选择菜单图标" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">跳转url</label>
				<div class="layui-input-block">
					<input type="text" name="url" required
						lay-verify="required" placeholder="请输入url，没有可以不填" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">回调方法</label>
				<div class="layui-input-block">
					<input type="text" name="method" required
						lay-verify="required" placeholder="请输入回调，没有可以不填" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">序号</label>
				<div class="layui-input-block">
					<input type="text" name="seq" required
						lay-verify="required" placeholder="请输入序号" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script src="${ctx}/static/js/layui/layui.js"></script>
		<script src="${ctx}/static/js/common.js"></script>
		<script>
		layui.config({
			base: '${ctx}/static/js/',
		})
		layui.use(['treeSelect', 'form', 'upload'], function(){
		  	var form = layui.form;
		  	var treeSelect= layui.treeSelect;
		  	var upload = layui.upload;
		  	var $ = layui.$;
		  
			//监听提交
			form.on('submit(formDemo)', function(data) {
				//$.post一般来说需要3个参数：url，参数，回调函数
				$.post('${ctx}/menu/save', data.field , function (e){
					if (e == "") {
						$('#refresh', parent.document).click();		//调用父页面（menu_list.jsp）中的id为refresh的元素的点击方法
						parent.layer.msg('添加成功', {icon: 1});		//高用父窗口中的layer来提示，这样关闭弹出窗后提示不会立马关闭
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					} else {
						alert("失败");
					}
				})
				return false;
			});
/* 
			//父级菜单树形下拉框
	        treeSelect.render({
	            elem: '#pid',
	            data: '${ctx}/menu/getParentMenu',
	            type: 'get',
	            placeholder: '请选择父级菜单',
	            search: true,
	            click: function(d){
	               	$('#pid').val(d.current.id);
	            },
	            success: function (d) {
	            	//treeSelect.checkNode('pid', 17);
	            	//$('#pid').val(17);
	            }
	        }); */
			
		});
		</script>
	</div>
</body>
</html>